import java.io.*;
import java.util.StringTokenizer;

public class 手写堆排序 {

    public static PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
    public static Read in = new Read();
    public static int MAXN = 100001;
    public static int n;
    public static int[] arr = new int[MAXN];
    public static void main(String[] args) throws IOException {
        n = in.nextInt();
        for (int i = 0; i < n; i++) {
            arr[i] = in.nextInt();
        }
        heapSort();
        for (int i = 0; i < n; i++) {
            out.print(arr[i] + " ");
        }
        out.close();
    }

    private static void heapSort() {
        for (int i = 0; i < n; i++) {
            heapInsert(i);
        }
        int size = n;
        while (size > 1) {
            swap(0,--size);
            heapify(0,size);
        }
    }

    private static void heapify(int i, int size) {
        int l = 2 * i + 1;
        while (l < size) {
            // 找到下面最强的
            int best = l + 1 < size && arr[l] < arr[l + 1] ? l + 1 : l;
            if (arr[i] > arr[best]) {
                break;
            }
            swap(i,best);
            i = best;
            l = 2 * best + 1;
        }
    }

    private static void heapInsert(int i) {
        while (arr[i] > arr[(i - 1) / 2]) {
            swap(i,(i - 1) / 2);
            i = (i - 1) / 2;
        }
    }

    private static void swap(int a, int b) {
        int tmp = arr[a];
        arr[a] = arr[b];
        arr[b] = tmp;
    }


    public static class Read {
        public static StringTokenizer st = new StringTokenizer("");
        public static BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
        String next() throws IOException {
            while (!st.hasMoreTokens()) {
                st = new StringTokenizer(bf.readLine());
            }
            return st.nextToken();
        }
        int nextInt() throws IOException {
            return Integer.parseInt(next());
        }

        long nextLong() throws IOException {
            return Long.parseLong(next());
        }
    }
}
